<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                paymentInfo: {
                    validators: {
                        notEmpty: {message: "付款信息不可为空"},
                        stringLength: {max: 2000, message: "付款信息最大长度为2000"}
                    }
                }
            }
        });
    }

    /**
     * 审核
     */
	<shiro:hasPermission name="back_gotoShopSettlementDetailPage_check">
    function check() {
        $("#myModalLabel_check").empty().text("审核");
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            if (selectedRow) {/**判断是否找到当前行**/
				if(selectedRow[0].status==2){
					 showMsg("审核已通过，不能审核！");
                    $("#btn_edit").attr("data-target", "");/**没有选中记录关闭对应的模态框**/
				}else if(selectedRow[0].status==4){
					 showMsg("已结算，不能审核！");
                    $("#btn_edit").attr("data-target", "");/**没有选中记录关闭对应的模态框**/
				}else if(selectedRow[0].status==1 || selectedRow[0].status==3){
					$("#btn_edit").attr("data-target", "#addOrEditModal_check");/**选中了记录后才可打开对应的模态框**/
					/**隐藏域**/
					$("#status_settlementId").val(selectedRow[0].settlementId);
					$("#status_"+selectedRow[0].status).attr("checked","checked");
				}
            }
        } else {
            $("#btn_edit").attr("data-target", "");/**没有选中记录关闭对应的模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>

    /**
     * 付款
     */
	<shiro:hasPermission name="back_gotoShopSettlementDetailPage_payment">
    function paymentInfo() {
        $("#myModalLabel").empty().text("付款信息");
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            if (selectedRow) {/**判断是否找到当前行**/
              	if(selectedRow[0].status==2){
                    $("#btn_paymentInfo").attr("data-target", "#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
                    /**隐藏域**/
                    $("#settlementId").val(selectedRow[0].settlementId);
                }else if(selectedRow[0].status==4){
                    $("#btn_paymentInfo").attr("data-target", "");/**没有选中记录关闭对应的模态框**/
                    showMsg("已结算，不能付款！");
				}else if(selectedRow[0].status==1 || selectedRow[0].status){
                    $("#btn_paymentInfo").attr("data-target", "");/**没有选中记录关闭对应的模态框**/
                    showMsg("请先通过审核！");
                }
            }
        } else {
            $("#btn_paymentInfo").attr("data-target", "");/**没有选中记录关闭对应的模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>
    
    function submitFormCheck() {
        var options = {
            url: $("#status_form").attr("action"),
            type : "post",
            dataType:"json",
            success : function(data) {
                if(data.success==true){
                    /** 先重置查询框的值**/
                    resetQueryForm();
                    /** 重新刷新列表数据**/
                    $("#tt").bootstrapTable('refresh');
                    /** 自动关闭弹出模态框窗口**/
                    $(".close").click();
                    showMsg("保存成功！");
                }else{
                    showMsg("保存失败！");
                }
            }
        };
        $("#status_form").ajaxSubmit(options);
    }

</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" >
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/shopSettlement/updateShopSettlementDetailPaymentInfo.sjson">
					<input id="settlementId" type="hidden" name="settlementId" noclear="true"/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>付款信息:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<textarea id="paymentInfo" class="form-control input-sm" type="text" name="paymentInfo" placeholder="请输入付款信息"></textarea>
									<span style="color:red">如：对方收款账号，交易号，金额，时间等</span>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>

	<div class="modal fade" id="addOrEditModal_check" tabindex="-1" role="dialog" aria-labelledby="myModalLabel_check" aria-hidden="true" data-backdrop="static" >
		<div class="modal-dialog" style="width:70%">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h5 class="modal-title" id="myModalLabel_check"></h5>
				</div>
				<div class="modal-body">
					<form id="status_form"  method="post" action="${basePath}/back/shopSettlement/updateShopSettlementDetailStatus.sjson">
						<input id="status_settlementId" type="hidden" name="settlementId" noclear="true"/>
						<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
							<tr>
								<td class="toright_td" width="150px"><span style="color:red">* </span>审核状态:&nbsp;&nbsp;</td>
								<td class="toleft_td" colspan="3">
									<input id="status_1"  type="radio" name="status" class="radioInput" value="1"/>待审核
									<input id="status_2"  type="radio" name="status" class="radioInput" value="2"/>审核通过
									<input id="status_3"  type="radio" name="status" class="radioInput" value="3"/>审核未通过
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" id="validateBtn__check" class="btn btn-primary"  onclick="submitFormCheck()">保存</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>

</div>

